﻿#include <stdio.h>
#include "OList.h"
#include "log_printf.h"

struct STU_T {
	char name[32];
	int age;
	double score;
	int num;
};

#define CONCAT(a, b) a##b

int main()
{
	logPrintfSetLogLevel(LOG_LIB_TRACE);
	//logPrintf(LOG_APP_ERROR, "APP ERROR\n");
	//logPrintf(LOG_APP_NOTICE, "APP NOTICE\n");
	//logPrintf(LOG_APP_TRACE, "APP TRACE\n");
	//logPrintf(LOG_LIB_ERROR, "LIB ERROR\n");
	//logPrintf(LOG_LIB_NOTICE, "LIB NOTICE\n");
	//logPrintf(LOG_LIB_TRACE, "LIB TRACE\n");

	struct STU_T s1 = { "li", 32, 7.9, 0 };
	struct STU_T s2 = { "sd", 23, 545.3, 1 };
	struct STU_T s3 = { "fds", 54, 34.6, 2 };
	struct STU_T s4 = { "vdds", 31, 543.1, 3 };
	struct STU_T s5 = { "wwr3", 65, 45.565, 4 };
	STU_T* students[5] = { &s1, &s2, &s3, &s4, &s5 };

	OList* list = initOListObj(sizeof(STU_T));
	for (int i = 0; i < 5; i++)
	{
		list->insert(list, NULL, students[i]);
	}

	for (int i = 0; i < list->size(list); i++)
	{
		STU_T* stu = (STU_T*)list->at(list, i);
		printf("姓名;%s\n年龄:%d\n分数:%f\n学号:%d\n", stu->name, stu->age, stu->score, stu->num);
		printf("---------------------------------------\n");
		
		//logPrintf(LOG_APP_NOTICE, "%d:%d\n", i + 1, *(int *)(list->at(list, i)));
	}
	printf("*****************%d*******************\n", __LINE__);
	OListIterator iter = list->iterAt(list, 2);
	struct STU_T ss1 = { "sd2", 232, 5452.32, 3 };


	//iter = list->iterAt(list, 4);
	list->eraseAt(list, 1);
	
	printf("*****************%d*******************\n", __LINE__);
	for (iter = list->begin(list); iter != list->end(list); iter = list->next(list, iter))
	{
		STU_T* stu = (STU_T*)list->value(list, iter);
		printf("姓名;%s\n年龄:%d\n分数:%f\n学号:%d\n", stu->name, stu->age, stu->score, stu->num);
		printf("---------------------------------------\n");
	}
	list->append(list, (void*)&s1);
	printf("*****************%d*******************\n", __LINE__);
	for (iter = list->begin(list); iter != list->end(list); iter = list->next(list, iter))
	{
		STU_T* stu = (STU_T*)list->value(list, iter);
		printf("姓名;%s\n年龄:%d\n分数:%f\n学号:%d\n", stu->name, stu->age, stu->score, stu->num);
		printf("---------------------------------------\n");
	}

	OList* list2 = initOListObj(sizeof(STU_T));
	for (int i = 0; i < 5; i++)
	{
		list2->insert(list2, NULL, students[i]);
	}

	return 0;
}


